from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-19 14:06:38.387915
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 19, Feb, 2021
Time: 14:06:43
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3028
Nobs: 207.000 HQIC: -47.1658
Log likelihood: 2388.83 FPE: 1.82790e-21
AIC: -47.7518 Det(Omega_mle): 1.19549e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.463976 0.138664 3.346 0.001
L1.Burgenland 0.077308 0.070975 1.089 0.276
L1.Kärnten -0.217790 0.060085 -3.625 0.000
L1.Niederösterreich 0.136675 0.164876 0.829 0.407
L1.Oberösterreich 0.245081 0.144547 1.696 0.090
L1.Salzburg 0.208970 0.076466 2.733 0.006
L1.Steiermark 0.097878 0.103333 0.947 0.344
L1.Tirol 0.140735 0.069050 2.038 0.042
L1.Vorarlberg -0.011547 0.063050 -0.183 0.855
L1.Wien -0.126672 0.135972 -0.932 0.352
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.476728 0.167619 2.844 0.004
L1.Burgenland 0.014301 0.085796 0.167 0.868
L1.Kärnten 0.355186 0.072632 4.890 0.000
L1.Niederösterreich 0.121015 0.199305 0.607 0.544
L1.Oberösterreich -0.134177 0.174730 -0.768 0.443
L1.Salzburg 0.194072 0.092434 2.100 0.036
L1.Steiermark 0.207171 0.124910 1.659 0.097
L1.Tirol 0.141748 0.083469 1.698 0.089
L1.Vorarlberg 0.159432 0.076215 2.092 0.036
L1.Wien -0.522346 0.164365 -3.178 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.315056 0.061484 5.124 0.000
L1.Burgenland 0.103328 0.031471 3.283 0.001
L1.Kärnten -0.018293 0.026642 -0.687 0.492
L1.Niederösterreich 0.078879 0.073107 1.079 0.281
L1.Oberösterreich 0.288000 0.064093 4.493 0.000
L1.Salzburg -0.000686 0.033906 -0.020 0.984
L1.Steiermark -0.016998 0.045818 -0.371 0.711
L1.Tirol 0.086657 0.030617 2.830 0.005
L1.Vorarlberg 0.108795 0.027957 3.892 0.000
L1.Wien 0.061129 0.060291 1.014 0.311
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222975 0.069912 3.189 0.001
L1.Burgenland -0.006103 0.035784 -0.171 0.865
L1.Kärnten 0.020962 0.030294 0.692 0.489
L1.Niederösterreich 0.039185 0.083128 0.471 0.637
L1.Oberösterreich 0.385022 0.072878 5.283 0.000
L1.Salzburg 0.087527 0.038553 2.270 0.023
L1.Steiermark 0.180749 0.052098 3.469 0.001
L1.Tirol 0.039388 0.034814 1.131 0.258
L1.Vorarlberg 0.086977 0.031789 2.736 0.006
L1.Wien -0.057737 0.068555 -0.842 0.400
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.517315 0.138974 3.722 0.000
L1.Burgenland 0.060721 0.071134 0.854 0.393
L1.Kärnten 0.017635 0.060219 0.293 0.770
L1.Niederösterreich -0.021109 0.165245 -0.128 0.898
L1.Oberösterreich 0.133491 0.144870 0.921 0.357
L1.Salzburg 0.058929 0.076637 0.769 0.442
L1.Steiermark 0.126531 0.103563 1.222 0.222
L1.Tirol 0.211347 0.069205 3.054 0.002
L1.Vorarlberg 0.026835 0.063191 0.425 0.671
L1.Wien -0.122429 0.136276 -0.898 0.369
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166586 0.097976 1.700 0.089
L1.Burgenland -0.013645 0.050149 -0.272 0.786
L1.Kärnten -0.009833 0.042455 -0.232 0.817
L1.Niederösterreich 0.109402 0.116497 0.939 0.348
L1.Oberösterreich 0.383007 0.102133 3.750 0.000
L1.Salzburg -0.019677 0.054029 -0.364 0.716
L1.Steiermark -0.021930 0.073012 -0.300 0.764
L1.Tirol 0.185378 0.048789 3.800 0.000
L1.Vorarlberg 0.044540 0.044549 1.000 0.317
L1.Wien 0.183634 0.096074 1.911 0.056
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.232169 0.126581 1.834 0.067
L1.Burgenland 0.056174 0.064791 0.867 0.386
L1.Kärnten -0.038445 0.054850 -0.701 0.483
L1.Niederösterreich -0.014778 0.150509 -0.098 0.922
L1.Oberösterreich -0.089727 0.131951 -0.680 0.497
L1.Salzburg 0.045170 0.069803 0.647 0.518
L1.Steiermark 0.386661 0.094328 4.099 0.000
L1.Tirol 0.481973 0.063034 7.646 0.000
L1.Vorarlberg 0.162025 0.057556 2.815 0.005
L1.Wien -0.219587 0.124124 -1.769 0.077
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080827 0.152610 0.530 0.596
L1.Burgenland 0.032576 0.078114 0.417 0.677
L1.Kärnten -0.076504 0.066128 -1.157 0.247
L1.Niederösterreich 0.275062 0.181459 1.516 0.130
L1.Oberösterreich -0.033556 0.159084 -0.211 0.833
L1.Salzburg 0.244200 0.084157 2.902 0.004
L1.Steiermark 0.136289 0.113725 1.198 0.231
L1.Tirol 0.058908 0.075995 0.775 0.438
L1.Vorarlberg 0.056779 0.069391 0.818 0.413
L1.Wien 0.229533 0.149647 1.534 0.125
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.585310 0.082772 7.071 0.000
L1.Burgenland -0.039297 0.042367 -0.928 0.354
L1.Kärnten -0.012616 0.035867 -0.352 0.725
L1.Niederösterreich -0.018938 0.098419 -0.192 0.847
L1.Oberösterreich 0.296632 0.086284 3.438 0.001
L1.Salzburg 0.018757 0.045645 0.411 0.681
L1.Steiermark 0.003510 0.061682 0.057 0.955
L1.Tirol 0.079033 0.041218 1.917 0.055
L1.Vorarlberg 0.121318 0.037636 3.223 0.001
L1.Wien -0.027623 0.081166 -0.340 0.734
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137574 0.034967 0.199252 0.251536 0.063074 0.108190 -0.049153 0.170187
Kärnten 0.137574 1.000000 0.012275 0.195713 0.165850 -0.117838 0.152121 0.005686 0.321752
Niederösterreich 0.034967 0.012275 1.000000 0.300205 0.082267 0.210708 0.127800 0.050125 0.361974
Oberösterreich 0.199252 0.195713 0.300205 1.000000 0.297592 0.292483 0.106567 0.075038 0.134396
Salzburg 0.251536 0.165850 0.082267 0.297592 1.000000 0.151024 0.057887 0.090940 -0.010390
Steiermark 0.063074 -0.117838 0.210708 0.292483 0.151024 1.000000 0.102678 0.104520 -0.104898
Tirol 0.108190 0.152121 0.127800 0.106567 0.057887 0.102678 1.000000 0.163763 0.167179
Vorarlberg -0.049153 0.005686 0.050125 0.075038 0.090940 0.104520 0.163763 1.000000 0.037376
Wien 0.170187 0.321752 0.361974 0.134396 -0.010390 -0.104898 0.167179 0.037376 1.000000